package com.boglond.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;


public class PropertyUtil {
    private static final Logger log = LoggerFactory.getLogger(PropertyUtil.class);


    private static final Map<String, String> PROPERTIES = new HashMap<>();

    static {
        try {
            Properties prop = new Properties();
            prop.load(new InputStreamReader(PropertyUtil.class.getClassLoader().getResourceAsStream("config.properties"), StandardCharsets.UTF_8));
            //处理重复的值.
            for (Map.Entry<Object, Object> entry : prop.entrySet()) {
                PROPERTIES.put(entry.getKey().toString().trim(), entry.getValue().toString().trim());
            }
        } catch (Exception e) {
            log.error(">> Property工具类异常,详细信息:{}", e);
            throw new RuntimeException(e);
        }
    }

    /**
     *通过key值去获取值.
     */
    public static String getValueByKey(String name) {
        return PROPERTIES.get(name);
    }



}
